package drrr.orm;

import drrr.common.SpringContext;

import javax.persistence.*;
import javax.persistence.Entity;

/**
 * Created by lirance on 15/5/22.
 */
@Entity
@Table(name = "roomMember", schema = "", catalog = "drrr")
@IdClass(RoomMemberEntityPK.class)
public class RoomMemberEntity extends drrr.orm.Entity {
    private int roomId;
    private int memberId;

    @Id
    @Column(name = "roomId", nullable = false, insertable = true, updatable = true)
    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        this.roomId = roomId;
    }

    @Id
    @Column(name = "memberId", nullable = false, insertable = true, updatable = true)
    public int getMemberId() {
        return memberId;
    }

    public void setMemberId(int memberId) {
        this.memberId = memberId;
    }

    /**
     * 获取用户实体
     * 请忽略错误
     *
     * @return
     */
    public UserEntity getMemberEntity() {
        return ((AllService) SpringContext.getBean("allService")).getUserService().getUserEntity(getMemberId());
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RoomMemberEntity that = (RoomMemberEntity) o;

        if (roomId != that.roomId) return false;
        if (memberId != that.memberId) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = roomId;
        result = 31 * result + memberId;
        return result;
    }
}
